{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 通过\"!命令\"来执行Linux命令"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### echo 打印字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "hello\r\n"
     ]
    }
   ],
   "source": [
    "!echo hello"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### ls 列出当前目录下的文件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Linux.ipynb  Untitled.ipynb  test.txt\r\n"
     ]
    }
   ],
   "source": [
    "!ls"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### date 获取当前时间"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Mon Apr 15 13:26:00 UTC 2019\r\n"
     ]
    }
   ],
   "source": [
    "!date"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### pwd 打印当前目录"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "/rapiro/notebook/chapter1_基础篇/1_Linux基础\r\n"
     ]
    }
   ],
   "source": [
    "!pwd"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### echo 输出字符串到文件，输出重定向"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "!echo \"12345\" > test.txt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### cat 查看文件内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12345\r\n"
     ]
    }
   ],
   "source": [
    "!cat test.txt"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### uname 显示系统信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Linux raspberrypi 4.14.98-v7+ #1200 SMP Tue Feb 12 20:27:48 GMT 2019 armv7l GNU/Linux\r\n"
     ]
    }
   ],
   "source": [
    "!uname -a"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### apt update 获取软件更新源"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Get:1 http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian stretch InRelease [15.0 kB]\n",
      "Get:2 http://mirrors.tuna.tsinghua.edu.cn/raspberrypi stretch InRelease [25.4 kB]\n",
      "Get:3 http://mirrors.tuna.tsinghua.edu.cn/raspbian/raspbian stretch/main armhf Packages [16.4 MB]\n",
      "Get:4 http://mirrors.tuna.tsinghua.edu.cn/raspberrypi stretch/main armhf Packages [222 kB]33m\n",
      "Fetched 16.7 MB in 12s (1362 kB/s)                                             \u001b[0m\u001b[33m\u001b[33m\u001b[33m\u001b[33m\u001b[33m\u001b[33m\u001b[33m\u001b[33m\u001b[33m\u001b[33m\u001b[33m\u001b[33m\n",
      "Reading package lists... Done\n",
      "Building dependency tree       \n",
      "Reading state information... Done\n",
      "11 packages can be upgraded. Run 'apt list --upgradable' to see them.\n"
     ]
    }
   ],
   "source": [
    "!apt update"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### apt install 安装软件"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Reading package lists... Done\n",
      "Building dependency tree       \n",
      "Reading state information... Done\n",
      "python3 is already the newest version (3.5.3-1).\n",
      "0 upgraded, 0 newly installed, 0 to remove and 11 not upgraded.\n"
     ]
    }
   ],
   "source": [
    "!apt install python3"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### pip3 list 查看已安装的python库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "\u001b[31mDEPRECATION: The default format will switch to columns in the future. You can use --format=(legacy|columns) (or define a format=(legacy|columns) in your pip.conf under the [list] section) to disable this warning.\u001b[0m\n",
      "absl-py (0.7.0)\n",
      "asn1crypto (0.24.0)\n",
      "astor (0.7.1)\n",
      "attrs (19.1.0)\n",
      "audioread (2.1.6)\n",
      "Automat (0.7.0)\n",
      "backcall (0.1.0)\n",
      "baidu-aip (2.2.13.0)\n",
      "bleach (3.1.0)\n",
      "bluepy (1.3.0)\n",
      "broadlink (0.9)\n",
      "certifi (2019.3.9)\n",
      "cffi (1.12.2)\n",
      "chardet (3.0.4)\n",
      "Click (7.0)\n",
      "constantly (15.1.0)\n",
      "cryptography (2.5)\n",
      "cssselect (1.0.3)\n",
      "cycler (0.10.0)\n",
      "decorator (4.3.2)\n",
      "defusedxml (0.5.0)\n",
      "entrypoints (0.3)\n",
      "Flask (1.0.2)\n",
      "gast (0.2.2)\n",
      "grpcio (1.18.0)\n",
      "h5py (2.9.0)\n",
      "hyperlink (18.0.0)\n",
      "idna (2.8)\n",
      "incremental (17.5.0)\n",
      "ipykernel (5.1.0)\n",
      "ipython (7.4.0)\n",
      "ipython-genutils (0.2.0)\n",
      "itsdangerous (1.1.0)\n",
      "jedi (0.13.3)\n",
      "Jinja2 (2.10.1)\n",
      "joblib (0.13.2)\n",
      "jsonschema (3.0.1)\n",
      "jupyter-client (5.2.4)\n",
      "jupyter-core (4.4.0)\n",
      "Keras (2.2.4)\n",
      "Keras-Applications (1.0.7)\n",
      "Keras-Preprocessing (1.0.9)\n",
      "kiwisolver (1.0.1)\n",
      "librosa (0.4.2)\n",
      "lxml (4.3.1)\n",
      "Markdown (3.0.1)\n",
      "MarkupSafe (1.1.1)\n",
      "matplotlib (3.0.2)\n",
      "mistune (0.8.4)\n",
      "nbconvert (5.4.1)\n",
      "nbformat (4.4.0)\n",
      "notebook (5.7.8)\n",
      "numpy (1.16.1)\n",
      "opencv-python (3.4.4.19)\n",
      "paho-mqtt (1.4.0)\n",
      "pandocfilters (1.4.2)\n",
      "parsel (1.5.1)\n",
      "parso (0.4.0)\n",
      "pexpect (4.7.0)\n",
      "pickleshare (0.7.5)\n",
      "pip (9.0.1)\n",
      "prometheus-client (0.6.0)\n",
      "prompt-toolkit (2.0.9)\n",
      "protobuf (3.6.1)\n",
      "ptyprocess (0.6.0)\n",
      "pyasn1 (0.4.5)\n",
      "pyasn1-modules (0.2.4)\n",
      "PyAudio (0.2.11)\n",
      "pycparser (2.19)\n",
      "PyCRC (1.21)\n",
      "pycryptodome (3.4.11)\n",
      "PyDispatcher (2.0.5)\n",
      "pygame (1.9.4.post1)\n",
      "Pygments (2.3.1)\n",
      "pygobject (3.22.0)\n",
      "PyHamcrest (1.9.0)\n",
      "pyOpenSSL (19.0.0)\n",
      "pyparsing (2.3.1)\n",
      "pyrsistent (0.14.11)\n",
      "python-dateutil (2.8.0)\n",
      "PyYAML (3.13)\n",
      "pyzmq (18.0.1)\n",
      "queuelib (1.5.0)\n",
      "requests (2.21.0)\n",
      "scikit-learn (0.20.2)\n",
      "scipy (1.2.1)\n",
      "Scrapy (1.6.0)\n",
      "Send2Trash (1.5.0)\n",
      "service-identity (18.1.0)\n",
      "setuptools (41.0.0)\n",
      "six (1.12.0)\n",
      "tensorboard (1.12.0)\n",
      "tensorflow (1.12.0)\n",
      "termcolor (1.1.0)\n",
      "terminado (0.8.2)\n",
      "testpath (0.4.2)\n",
      "tornado (6.0.2)\n",
      "traitlets (4.3.2)\n",
      "Twisted (18.9.0)\n",
      "urllib3 (1.24.1)\n",
      "w3lib (1.20.0)\n",
      "wcwidth (0.1.7)\n",
      "webencodings (0.5.1)\n",
      "Werkzeug (0.14.1)\n",
      "wheel (0.33.1)\n",
      "zope.interface (4.6.0)\n"
     ]
    }
   ],
   "source": [
    "!pip3 list"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### pip3 install 安装新的python库"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: Flask in /usr/local/lib/python3.5/dist-packages\n",
      "Requirement already satisfied: Jinja2>=2.10 in /usr/local/lib/python3.5/dist-packages (from Flask)\n",
      "Requirement already satisfied: click>=5.1 in /usr/local/lib/python3.5/dist-packages (from Flask)\n",
      "Requirement already satisfied: itsdangerous>=0.24 in /usr/local/lib/python3.5/dist-packages (from Flask)\n",
      "Requirement already satisfied: Werkzeug>=0.14 in /usr/local/lib/python3.5/dist-packages (from Flask)\n",
      "Requirement already satisfied: MarkupSafe>=0.23 in /usr/local/lib/python3.5/dist-packages (from Jinja2>=2.10->Flask)\n"
     ]
    }
   ],
   "source": [
    "!pip3 install Flask "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "jupyter notebook 更多使用，参考https://zhuanlan.zhihu.com/p/32320214"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
